<template>
	<view>
		<view class="view_title">
			请选择系统
		</view>
		<view class="card_back" @click="goToPage('1', '/pages/car/index')"
			style="background-image: url('');">
			<div class="card_title">
				工程车辆安全调度系统
			</div>
			<div class="card_content">
				包括了车辆实时定位、历史轨迹、超速预警、受控区域等功能...
			</div>
		</view>
		<view class="card_back" @click="goToPage2('/pages/index/index')"
			style="background-image: url('');">
			<div class="card_title">
				隧道专家咨询
			</div>
			<div class="card_content">
				内含海量专家库，可对开采隧道遇到的各种疑难杂症进行解答
			</div>
		</view>
		<view class="card_back1" @click="goToPage('2', '/pages/material/equipment_material_index')"
			style="background-image: url('https://czsc.oss-cn-beijing.aliyuncs.com/mini/material.jpg');">
			<div class="card_title">
				设备、物资出入库管理
			</div>
			<div class="card_content">
				可对物资进行入库、出库管理，实时生成库存量，对各物资做到心中有数
			</div>
		</view>
	</view>
</template>

<script>
	import { BaseUrl } from '@/util/util.js';
	const PrefixUrl = BaseUrl();
	export default {
		data() {
			return {

			}
		},
		onShow() {
			console.log(uni.getStorageSync('openid'))
			if (uni.getStorageSync('openid') === '' || new Date() - uni.getStorageSync('getday') > 1296000000) {
				uni.redirectTo({
					url: '/pages/sq/sq'
				});
			} else {
				uni.request({
					method: 'POST',
					// url: 'https://www.gjegm.ltd/czsczq/wxuser/getOpenid',
					url: PrefixUrl + '/wxuser/getOpenid',
					data: {
						openid: uni.getStorageSync('openid')
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: (res) => {
						
						if (res.data.obj) {
							console.log(res.data.obj2.wxPermission)
							uni.removeStorageSync('token');
							uni.setStorageSync('userid', res.data.obj2.userid);
							uni.setStorageSync('username', res.data.obj2.username);
							uni.setStorageSync('userbdst', res.data.obj2.bdst);
							uni.setStorageSync('userPermission', res.data.obj2.wxPermission);
							// 获得token、默认初始查询已回答
							uni.request({
								method: 'GET',
								url: PrefixUrl + '/userinfo/getToken',
								data: {
									name: '1',
									bdst: '1',
									department: '1'

								},
								header: {
									'content-type': 'application/x-www-form-urlencoded'
								},
								success: (res) => {
									uni.setStorageSync('token', res.data);
								}
							});

						} else {
							uni.redirectTo({
								url: '/pages/band/band_openid'
							});
						}

					}
				});
			}
		},
		methods: {
			goToPage(val, url) {
				if (uni.getStorageSync('userPermission').indexOf(val) >= 0) {
					//保留当前页面，跳转到应用内的某个页面，使用uni.navigateBack可以返回到原页面。
					uni.navigateTo({
						url: url
					});
				} else {
					uni.showToast({
						title: '暂无权限，请联系科信部开通权限',
						mask: true,
						icon: 'none'
					})
				}
			},
			goToPage2(url) {
				if (uni.getStorageSync('userPermission').indexOf('3') >= 0) {
					//保留当前页面，跳转到应用内的某个页面，使用uni.navigateBack可以返回到原页面。
					//关闭所有页面，打开到应用内的某个页面。
					uni.switchTab({
						url: url
					});
				} else {
					uni.showToast({
						title: '暂无权限，请联系科信部开通权限',
						mask: true,
						icon: 'none'
					})
				}


			}

		}
	}
</script>

<style>
	.view_title {
		color: black;
		font-size: 48rpx;
		font-weight: bold;
		text-align: center;
		margin-top: 10%;
		margin-bottom: 10%;
	}

	.card_back {
		width: calc(100% - 100rpx);
		background-color: burlywood;
		margin: 40rpx 20rpx;
		border-radius: 20rpx;
		text-align: center;
		padding: 30rpx;
		background-size: 100%;
	}

	.card_back1 {
		width: calc(100% - 100rpx);
		background-color: burlywood;
		margin: 40rpx 20rpx;
		border-radius: 20rpx;
		text-align: center;
		padding: 30rpx;
		background-size: 90%;
	}

	.card_back:hover {
		opacity: 0.8;
		cursor: pointer;
	}

	.card_title {
		padding: 40rpx;
		font-size: 48rpx;
		color: white;
	}

	.card_content {
		color: white;
	}
</style>
